package cn.piaoyi.web.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import cn.piaoyi.bean.Admin;
import cn.piaoyi.bean.Category;
import cn.piaoyi.bean.Goods;
import cn.piaoyi.comm.Constant;
import cn.piaoyi.comm.Util;
import cn.piaoyi.exception.PiaoyiException;
import cn.piaoyi.service.AdminService;
import cn.piaoyi.service.CategoryService;
import cn.piaoyi.service.GoodsService;
import cn.piaoyi.service.PosterService;
import cn.piaoyi.service.web.PageList;
import cn.piaoyi.service.web.Pages;
import cn.piaoyi.web.interceptor.UserSessionAware;
import cn.piaoyi.web.servlet.AdminSession;
import cn.piaoyi.web.servlet.UserSession;
import cn.piaoyi.web.ui.OptionsInt;
import cn.piaoyi.web.ui.OptionsLong;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.SessionAware;

public class Index extends BaseAction implements UserSessionAware{
	private static final Log logger = LogFactory.getLog(Index.class);
	
	private GoodsService goodsService;
	private CategoryService categoryService;
	private PosterService posterService;

	public GoodsService getGoodsService() {
		return goodsService;
	}

	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}
	
	public CategoryService getCategoryService() {
		return categoryService;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}
	
	public PosterService getPosterService() {
		return posterService;
	}

	public void setPosterService(PosterService posterService) {
		this.posterService = posterService;
	}
	
	private UserSession userSession;
	public UserSession getUserSession() {
		return userSession;
	}

	public void setUserSession(UserSession userSession) {
		this.userSession = userSession;
	}
	
	private PageList pageList;
	private List posterList;
	private List concertList;
	private List tourList;
	private List gundongList;

	public PageList getPageList() {
		return pageList;
	}

	public void setPageList(PageList pageList) {
		this.pageList = pageList;
	}

	public List getPosterList() {
		return posterList;
	}

	public void setPosterList(List posterList) {
		this.posterList = posterList;
	}

	public List getConcertList() {
		return concertList;
	}

	public void setConcertList(List concertList) {
		this.concertList = concertList;
	}

	public List getTourList() {
		return tourList;
	}

	public void setTourList(List tourList) {
		this.tourList = tourList;
	}

	public List getGundongList() {
		return gundongList;
	}

	public void setGundongList(List gundongList) {
		this.gundongList = gundongList;
	}

	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return INPUT;
		}
	}

	/**
	 * 初始页
	 */
	public String index(){
		Pages pages = new Pages();
		pages.setPage(this.getPage());
		pages.setPerPageNum(16);
		if (this.getTotal() > 0) {
			pages.setTotalNum(this.getTotal());
		}
		pages.setFileName("/index.action");
		this.setPageList(this.getGoodsService().findGoodses(userSession.getCityId(),"", "", 1, -1, "orders", 0, pages));
		
		this.posterList = this.getPosterService().findPosters("orders", 0);
		this.concertList = this.getGoodsService().findGoodses(userSession.getCityId(),Constant.CATEGORY_CONCERT, "", 1, -1,"id", 1, 0, 2);
		this.tourList = this.getGoodsService().findGoodses(userSession.getCityId(),Constant.CATEGORY_TOUR, "", 1, -1,"id", 1, 0, 6);
		return SUCCESS;
	}

	/**
	 * 滚动
	 */
	public String gundong(){
		this.gundongList = this.getGoodsService().findGoodses(userSession.getCityId(),"", "", 1, -1,"id", 1, 0, 10);
		return "gundong";
	}
}
